package y24.m5.sql;

import com.mysql.cj.jdbc.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.SQLException;

public class Mysql {
    public Connection getConnection(String user,String password,String databases) throws SQLException {
        DataSource dataSource = new MysqlDataSource();
        String url = "jdbc:mysql://127.0.0.1:3306/" + databases;
        ((MysqlDataSource)dataSource).setUrl(url);
        ((MysqlDataSource)dataSource).setUser(user);
        ((MysqlDataSource)dataSource).setPassword(password);
        return dataSource.getConnection();
    }
}

